import Vue from 'vue'
import VueRouter from 'vue-router'

// 注册路由
Vue.use(VueRouter)
// 添加路由规则
const routes = [
  {
    name:'login',
    path:'/login',
    component:()=>import('@/views/Login/Login')
  },
  {
    name:'reg',
    path:'/reg',
    component:()=>import('@/views/Reg/Reg')
  },
  {
    name:'main',
    path:'/',
    component:()=>import('../views/Main/Main.vue'),
    // 重定向到home页面
    redirect:'/home',
    // 二级路由嵌套使用
    children:[
      {
        // 二级路由path可以不用加斜杠
        path:'home',
        name:'home',
        component:()=>import('@/views/Menus/Home/Home.vue')
      },
      // 修改用户信息
      {
        path:'user-info',
        name:'userInfo',
        component:()=>import('@/views/Menus/User/UserInfo.vue')
      },
      // 修改用户头像
      {
        path:'user-avatar',
        name:'UserAvatar',
        component:()=>import('@/views/Menus/User/UserAvatar.vue')
      },
      // 重置密码
      {
        path:'user-pwd',
        name:'userPwd',
        component:()=>import('@/views/Menus/User/UserPwd.vue')
      },
      // 文章分类
      {
        path:'art-cate',
        name:'artCate',
        component:()=>import('@/views/Menus/Article/ArtCate.vue')
      },
      {
        path:'art-list',
        name:'artList',
        component:()=>import('@/views/Menus/Article/ArtList.vue')
      },

    ]
  }
]
// 创建路由实例
const router = new VueRouter({
  routes
})

// 把下面的代码粘贴到路由模块中对应的位置，即可防止路由报错的问题  
// 解决路由重复跳转相同页面的问题
const RouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (to) {
  return RouterPush.call(this, to).catch(err => err)
}

// 暴露路由
export default router
